# @ModuleName: bo
# @Author: zxl
# @Time: 2024/6/15 11:13'
from selenium.webdriver.common.by import By

from quote.base.usebrowserteacher import UseBrowser


class BrowserOperation:



    def __init__(self,driver):
        self.driver = driver

    def search_element(self,type,locator):
        # if type.lower()
        type = type.lower()
        element = self.driver.find_element(type,locator)
        # 检查是否找到了对应的 By 类型
        if element is None:
            raise ValueError(
                f"Invalid type: {type}. Expected one of ['id', 'name', 'xpath', 'link_text', 'partial_link_text', 'tag_name', 'class_name', 'css_selector']")

        # 使用找到的 By 类型和 locator 来定位元素
        element = self.driver.find_element(type, locator)
        return element
    # 输入操作
    def input_text(self,type,locator,text):
        self.search_element(type,locator).send_keys(text)


    def click_element(self,type,locator):
        self.search_element(type,locator).click()

    def open_url(self,url):
        self.driver.get(url)


if __name__ == '__main__' :
    pass
    ub = UseBrowser()
    bo = BrowserOperation(UseBrowser.driver)
    bo.open_url('http://localhost:8080/JavaPrj_6/')
    bo.input_text('name','username','admin')
    bo.input_text('name','password','admin')
    bo.click_element('name','submit')
    ub.quit()
